#!/bin/sh

set -u
set -e
trap onexit INT
trap onexit TERM
trap onexit EXIT

TMPDIR=

onexit()
{
	if [ ! "$TMPDIR" = "" ]; then
		rm -rf $TMPDIR
	fi
}

PACKAGE_NAME=libjpeg-turbo
VERSION=1.1.1
SRCDIR=/home/tgall/libjpeg-turbo-android/wip

umask 022
rm -f $PACKAGE_NAME-$VERSION-cygwin.tar.bz2
TMPDIR=`mktemp -d /tmp/ljtbuild.XXXXXX`
__PWD=`pwd`
make install DESTDIR=$TMPDIR/pkg mandir=/opt/$PACKAGE_NAME/man
rm $TMPDIR/pkg/opt/$PACKAGE_NAME/lib/*.la
DOCDIR=$TMPDIR/pkg/usr/share/doc/$PACKAGE_NAME-$VERSION
mkdir -p $DOCDIR
install -m 644 $SRCDIR/README-turbo.txt $DOCDIR
install -m 644 $SRCDIR/README $DOCDIR
install -m 644 $SRCDIR/libjpeg.txt $DOCDIR
install -m 644 $SRCDIR/usage.txt $DOCDIR
install -m 644 $SRCDIR/LICENSE.txt $DOCDIR
install -m 644 $SRCDIR/LGPL.txt $DOCDIR
ln -fs lib $TMPDIR/pkg/opt/$PACKAGE_NAME/lib32
cd $TMPDIR/pkg
tar cfj ../$PACKAGE_NAME-$VERSION-cygwin.tar.bz2 *
cd $__PWD
mv $TMPDIR/*.tar.bz2 .

exit 0
